<template>
  <div class="card-item">
    <div class="item-img" @click="toDetail">
      <img :src="obj.src" />
    </div>

    <div class="item-bottom">
      <div class="bottom-price">
        <span class="price-money">￥{{ obj.price }}</span>
        <span class="price-discount">{{ obj.discount }}</span>
      </div>

      <div class="bottom-name" @click="addToCat">
        <span class="name-title">{{ obj.name }}</span>
        <span class="name-count">{{ obj.count }}</span>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { defineProps } from "vue";
import { useStore } from "vuex";
import { useRouter } from "vue-router";
import { PARAMS } from "@/config/params";

const store = useStore();
const roter = useRouter();

const poprs = defineProps({
  obj: Object,
});

const addToCat = () => {
  store.commit("myCat/addToList", poprs.obj);
};

const toDetail = () => {
  // sessionStorage.setItem(PARAMS.LIST_TO_DETAIL, JSON.stringify(poprs.obj));

  roter.push({ path: `/detail/${poprs.obj.id}` });
};
</script>

<style lang="less" scoped>
.card-item {
  display: flex;
  flex-direction: column;
  padding: 0 20px;

  .item-img {
    width: 5.04rem;
    height: 5.04rem;

    > img {
      height: 100%;
      width: 100%;
    }
  }
}
</style>
